/**
 * 简化的平台处理模块导出
 */

// 接口导出
export * from './interfaces';

// 平台处理器
export { ZhihuPlatform } from './ZhihuPlatform';
export { ToutiaoPlatform } from './ToutiaoPlatform';
export { WechatMpPlatform } from './WechatMpPlatform';
export { XiaohongshuPlatform } from './XiaohongshuPlatform';

// 平台处理器工厂
import {
  PublishPlatform,
  IPlatformHandler
} from './interfaces';
import { ZhihuPlatform } from './ZhihuPlatform';
import { ToutiaoPlatform } from './ToutiaoPlatform';
import { WechatMpPlatform } from './WechatMpPlatform';
import { XiaohongshuPlatform } from './XiaohongshuPlatform';
import { createLogger } from '../../utils/logger';

/**
 * 平台处理器工厂
 */
export class PlatformHandlerFactory {
  /**
   * 创建平台处理器
   */
  static createHandler(platform: PublishPlatform): IPlatformHandler {
    const logger = createLogger(`Platform.${platform}`);

    switch (platform) {
      case PublishPlatform.ZHIHU:
        return new ZhihuPlatform(logger);

      case PublishPlatform.TOUTIAO:
        return new ToutiaoPlatform(logger);

      case PublishPlatform.WECHAT_MP:
        return new WechatMpPlatform(logger);

      case PublishPlatform.XIAOHONGSHU:
        return new XiaohongshuPlatform(logger);

      default:
        throw new Error(`Unsupported platform: ${platform}`);
    }
  }

  /**
   * 获取所有支持的平台
   */
  static getSupportedPlatforms(): PublishPlatform[] {
    return [
      PublishPlatform.ZHIHU,
      PublishPlatform.TOUTIAO,
      PublishPlatform.WECHAT_MP,
      PublishPlatform.XIAOHONGSHU
    ];
  }

  /**
   * 检查平台是否支持
   */
  static isSupported(platform: PublishPlatform): boolean {
    return this.getSupportedPlatforms().includes(platform);
  }
}

/**
 * 便捷函数：创建平台处理器
 */
export const createPlatformHandler = PlatformHandlerFactory.createHandler;

/**
 * 便捷函数：获取支持的平台列表
 */
export const getSupportedPlatforms = PlatformHandlerFactory.getSupportedPlatforms;

/**
 * 便捷函数：检查平台支持
 */
export const isPlatformSupported = PlatformHandlerFactory.isSupported;

